package com;

import io.prediction.Event;

import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;

import com.PredictionIoService;
import com.util.Identities;




public class ApiDemo {

	
	
	PredictionIoService predictionIoService = new PredictionIoService();
	

	@Before
	public void setup() {
		predictionIoService.setAccessKey("1dhoNKMPTP-MnwEJIt_CHiisE9E_tYKe65HS3WTMDFsC2ERrMMgOU3UTiCY0pLHm");
		predictionIoService.setPredictionioUrl("http://96.90.248.213:7070");
	}
	
	
	@Test
	public void testCreatEvent() {
		
		Thread thread = new Thread(getRunnable("entityTypeTest1","eventTest1"));
		thread.start();
		
		Thread thread2 = new Thread(getRunnable("entityTypeTest2","eventTest2"));
		thread2.start();
		
		Thread thread3 = new Thread(getRunnable("entityTypeTest3","eventTest3"));
		thread3.start();
		
		while(true){
			
		}
		
	}
	
	 Runnable  getRunnable(String entityType,String eventStr){
		 Runnable task = () -> {
			 Integer i = 300;
				 while (i !=0) {
					 Event event = new Event();
						event.event(eventStr);
						event.entityType(entityType);
						event.entityId(Identities.uuid2());
						event.eventTime(new DateTime());
						event.property("testKey", "testValue"+i);
						predictionIoService.creatEvent(event);		
					i--;
				}			
			};
		return task;
		
	}
	
	
	
}
